package com.giaothong.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.giaothong.R;
import com.giaothong.db.DatabaseManager;
import com.giaothong.ui.base.BaseActivity;
import com.giaothong.utils.SessionData;

public class SplashActivity extends BaseActivity {
	/**
	 * The time splash view will be shown before move to other activity Default
	 * value: 1000 mili seconds (1 second)
	 */
	private static final int SPLASH_VIEW_TIME = 2000;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.layout_splash);

		// init app's session data
		SessionData.clearAllSessionData();
		initAppSessionData();

		// if not login then goto verify Phone
		Handler handler = new Handler();
		handler.postDelayed(new Runnable() {

			public void run() {
				endSplashView();
			}
		}, SPLASH_VIEW_TIME);
	}

	/**
	 * init SessionData
	 */
	private void initAppSessionData() {
		SessionData.setDatabaseManager(new DatabaseManager(this));
		SessionData.setDb(SessionData.getDatabaseManager().getWritableDatabase());
	}

	/**
	 * end the Splash activity
	 */
	protected void endSplashView() {
		Intent intent = new Intent(this, LoginActivity.class);
		startActivityForResult(intent, 1);
		finish();
	}

}
